package pl.edu.agh.neuraleconomy.ui.component;

import java.util.Date;

import lombok.Getter;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import pl.edu.agh.neuraleconomy.ui.util.UIUtils;

public class NewSimulationDialog extends OkCancelDialog{

	@Getter
	private Date startDate;
	@Getter
	private Double startMoney;
	@Getter
	private String name;
	
	private DateTime dateComponent;
	private Text moneyComponent;
	private Text nameComponent;
	
	public NewSimulationDialog(Shell parentShell) {
		super(parentShell);
	}

	@Override
	protected void init(Composite parent) {
		parent.setLayout(new GridLayout(2, false));
		
		(new Label(parent, SWT.NONE)).setText("Start date");
		dateComponent = new DateTime(parent, SWT.DATE | SWT.DROP_DOWN);
		
		(new Label(parent, SWT.NONE)).setText("Start money");
		moneyComponent = new Text(parent, SWT.NONE);
		moneyComponent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		moneyComponent.setText("10000");
		
		(new Label(parent, SWT.NONE)).setText("Name");
		nameComponent = new Text(parent, SWT.NONE);
		nameComponent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		nameComponent.setText("untitled");
	}

	@Override
	protected void saveInput() {
		startDate = UIUtils.getDateFromDateTimeWidget(dateComponent);
		startMoney = Double.parseDouble(moneyComponent.getText());
		name = nameComponent.getText();
	}

	@Override
	protected boolean validateInput() {
		try{
			UIUtils.getDateFromDateTimeWidget(dateComponent);
			Double.parseDouble(moneyComponent.getText());
			return nameComponent.getText().trim().length() > 0;
		}catch(Exception e){
			return false;
		}
	}

}
